import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
//import 'element-ui/lib/theme-chalk/index.css'
import '../theme/index.css';
import './assets/css/theme/theme2/index.css';
import './assets/css/theme/theme1/index.css';
import myFunc from "./myFunc";
import myType from "./myType"
import VueGridLayout from "vue-grid-layout/src/components";
// 设置反向代理，前端请求默认发送到 http://localhost:8090/api
var axios = require('axios')
axios.defaults.baseURL = 'http://localhost:8090/api'

// request拦截器,在请求之前做一些处理
axios.interceptors.request.use(
  config => {

    // 从vuex读取token的值,给请求头添加token
    if (store.state.user.token) {
      //config.headers['token'] = store.state.user.token;
    }
    //console.log('config',config);
    return config
  },
  error => {
    console.log(error) // for debug
    Promise.reject(error)
  }
)

// 全局注册，之后可在其他组件中通过 this.$axios 发送数据
Vue.prototype.$axios = axios
Vue.config.productionTip = false

Vue.use(myFunc)
Vue.use(ElementUI)
Vue.use(myType)
Vue.use(VueGridLayout);
var GridLayout=VueGridLayout.GridLayout;
var GridItem=VueGridLayout.GridItem;
//钩子函数判断是否拦截
router.beforeEach((to, from, next) => {
  console.log(from);
    if (to.meta.requireAuth) {
      if (store.state.user.isOnline) {
        next()
      } else {
        next({
          path: 'login',
          query: {redirect: to.fullPath}
        })
      }
    } else {
      next()
    }
  }
)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
